DROP TABLE IF EXISTS vendors."PharmacyProductApproval";

CREATE TABLE vendors."PharmacyProductApproval" (
	"PharmacyProductApprovalId" bigserial NOT NULL,
	"PharmacyProductId" int4 NULL,
	"PharmacyStockId" int4 NULL,
	"PurchaseRate" numeric NULL,
	"Mrp" numeric NULL,
	"SupplierId" int4 NULL,
	"TenderStatusId" int4 NULL,
	"PharmacyProductRequestId" int4 NULL,
	"CreatedBy" int4 NULL,
	"CreatedDate" timestamp NULL,
	CONSTRAINT "PharmacyProductApproval_pkey" PRIMARY KEY ("PharmacyProductApprovalId"),
	CONSTRAINT "PharmacyProductApproval_CreatedBy_fkey" FOREIGN KEY ("CreatedBy") REFERENCES public."Account"("AccountId"),
	CONSTRAINT "PharmacyProductApproval_PharmacyProductId_fkey" FOREIGN KEY ("PharmacyProductId") REFERENCES public."PharmacyProduct"("PharmacyProductId"),
	CONSTRAINT "PharmacyProductApproval_PharmacyProductRequestId_fkey" FOREIGN KEY ("PharmacyProductRequestId") REFERENCES vendors."PharmacyProductRequest"("PharmacyProductRequestId"),
	CONSTRAINT "PharmacyProductApproval_PharmacyStockId_fkey" FOREIGN KEY ("PharmacyStockId") REFERENCES public."PharmacyStock"("PharmacyStockId"),
	CONSTRAINT "PharmacyProductApproval_SupplierId_fkey" FOREIGN KEY ("SupplierId") REFERENCES public."Supplier"("SupplierId"),
	CONSTRAINT "PharmacyProductApproval_TenderStatusId_fkey" FOREIGN KEY ("TenderStatusId") REFERENCES vendors."TendorStatus"("TenderStatusId")
);
insert into vendors."TendorStatus" ("Status")
values ('Moved To Tender');

-------------



create table vendors."TenderRequestSupplierHeader"(
			"TenderRequestSupplierHeaderId" bigserial primary key,			
			"TenderStatusId" int references vendors."TendorStatus"("TenderStatusId"),			
			"TenderRaisedBy" int references "Account"("AccountId"),
			"SupplierId" int references "Supplier"("SupplierId"), 
			"TenderRaisedDate" timestamp  without time zone,
			"IsCompleteAccepted" boolean default false,
			"AcceptedDate" timestamp  without time zone,
			"IsCompleteRejected" boolean default false,
			"CompleteRejectedDate" timestamp without time zone	,
			"CompleteRejectionComment" text
);

create table vendors."TenderRequestSupplierDetail"(
			"TenderRequestSupplierDetailId" bigserial primary key,
			 "TenderRequestSupplierHeaderId" bigint references vendors."TenderRequestSupplierHeader"("TenderRequestSupplierHeaderId"),
			 "PharmacyProductApprovalId" bigint references vendors."PharmacyProductApproval"("PharmacyProductApprovalId"),
			 "VendorMrp" numeric,
			 "VendorPurchaseRate" numeric,
			 "TenderStatusId" int references vendors."TendorStatus"("TenderStatusId"),
			 "VendorRejected" boolean default false,
			"VendorRejectedDate" timestamp without time zone,
			"RejectionComment" text
);

-------


insert into vendors."TendorStatus" ("Status")
values ('Pending Vendor Acceptance');


insert into vendors."TendorStatus" ("Status")
values ('PO Sent');

-----------